<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document-admin</title>
</head>
<!-- 引入样式 -->
<link rel="stylesheet" href="../../plugins/element-ui/lib/theme-chalk/index.css"/>
<!--<link rel="stylesheet" href="../../styles/common.css" />-->
<link rel="stylesheet" href="../../styles/page.css" />
<body>
<div class="dashboard-container" id="admin-app">
    <div class="container">
        <div class="tableBar" style="justify-content: flex-start;">
            <el-input v-model="input" placeholder="请输入学生名" style="width: 200px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
            <el-input v-model="input1" placeholder="请输入班级名" style="width: 200px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
            <el-input v-model="input2" placeholder="请输入考研或就业" style="width: 200px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
        </div>
        <div class="tableBar" style="justify-content: flex-start;">
            <el-input v-model="input3" placeholder="请输入学校" style="width: 200px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
            <el-input v-model="input4" placeholder="请输入缴费状态" style="width: 200px" clearable @keyup.enter.native="handleQuery">
                <i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
            </el-input>
            <el-button type="primary" style="position: absolute;right: 28px" @click="dialogVisible = true">
                导出学生缴费情况
            </el-button>
        </div>
        <!--  弹出框 选择表头 -->
        <el-dialog title="选择想要导出的列" :visible.sync="dialogVisible" width="30%">
            <el-checkbox-group v-model="headNames" @change="logS()">
                <el-checkbox label="name">学生姓名</el-checkbox>
                <el-checkbox label="phone">电话</el-checkbox>
                <el-checkbox label="channelName">渠道</el-checkbox>
                <el-checkbox label="sid">学号</el-checkbox>
                <el-checkbox label="school">学校</el-checkbox>
                <el-checkbox label="major">专业</el-checkbox>
                <el-checkbox label="grade">入学年份</el-checkbox>
                <el-checkbox label="clazzName">班级名</el-checkbox>
                <el-checkbox label="status">状态</el-checkbox>
                <el-checkbox label="gone">去向</el-checkbox>
                <el-checkbox label="payStatus">缴费状态</el-checkbox>
                <el-checkbox label="payCount">已缴金额</el-checkbox>
            </el-checkbox-group>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary"  @click="outputStatus()">确 定</el-button>
            </span>
        </el-dialog>
        <!--管理员分页展示table-->
        <el-table :data="tableData" stripe class="tableBox">
            <el-table-column prop="name" label="学生姓名" ></el-table-column>
            <el-table-column prop="sid" label="学号"></el-table-column>
            <el-table-column prop="school" label="学校"></el-table-column>
            <el-table-column prop="major" label="专业"></el-table-column>
            <el-table-column prop="grade" label="入学年份"></el-table-column>
            <el-table-column prop="clazzName" label="班级名"></el-table-column>
            <el-table-column prop="payStatus" label="缴费状态"></el-table-column>
            <el-table-column prop="payCount" label="已缴金额"></el-table-column>
            <el-table-column prop="status" label="状态"></el-table-column>
            <el-table-column fixed="right" label="操作" width="160" align="center">
                <template slot-scope="scope">
                    <el-button type="text" size="small" class="blueBug" @click="addAdminHandle(scope.row.id)">
                        查看详情
                    </el-button>
                    <el-button type="text" size="small" class="blueBug" @click="pay(scope.row.id)"
                               v-if="scope.row.payStatus!='已完成'">
                        缴费
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--page-sizes 条目数 -->
        <el-pagination
                class="pageList"
                :page-sizes="[20,30,40,50]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="counts"
                :current-page.sync="page"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
</div>
</body>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/lib/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/student.js"></script>
<script src="../../js/bianliang.js"></script>
<script>
    new Vue({
        el: '#admin-app',
        data() {
            return {
                headNames: ['name','phone','channelName','sid','school','major','grade','clazzName','status','gone','payStatus','payCount'],
                dialogVisible:false,
                input: '',
                input1: '',
                input2: '',
                input3: '',
                input4: '未完成',
                counts: 0,
                page: 1,
                pageSize: 20,
                tableData : [],
                id : '',
                status : '',
                datas:{
                    'name':'',
                    'sid':'',
                    'school':'',
                    'major':'',
                    'grade':'',
                    'clazzName':'',
                    'status':'',
                    'gone':'',
                    'payStatus':'',
                    'payCount':''
                }
            }
        },
        computed: {},

        /*vue初始化挂载函数*/
        created() {
            this.init();
            // alert(1439057691107037185);//js失去精度测试
            if(localStorage.getItem('userInfo')!=null){
                //获取当前登录管理员的账号，并赋值给模型数据
                this.user = JSON.parse(localStorage.getItem('userInfo')).username;
            }
        },
        mounted() {
        },
        methods: {
            logS(){
                console.log(this.headNames)
            },
            returnMoney(id){
                this.$confirm('确认退款?', '提示', {
                    'confirmButtonText': '确定',
                    'cancelButtonText': '取消',
                    'type': 'warning'
                }).then(() => {//点击确定执行
                    returnCount(id).then(res => {//请求结果处理
                        if (String(res.code) === '1') {
                            this.$message.success('已退款！');
                        }else{
                            this.$message.error(res.msg)
                        }
                        this.init()
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })
                })
            },
            pay(st){
                window.parent.menuHandle({
                    id: '1',
                    url: '/back/page/stuFlow/pay.html?id='+st,//跳转到add.html页面并携带一个id参数
                    name: '缴费操作'
                },true)
            },
            outputStatus(){
                this.dialogVisible = false
                var name = this.input
                var clazzName = this.input1
                var study = this.input2
                var school = this.input3
                var payStatus = this.input4
                var url = downloadurl+"/student/output?includeColumnFiledNames="+this.headNames
                    +"&name="+name+"&clazzName="+clazzName+"&study="+study+"&school="+school+"&payStatus="+payStatus
                console.log(url)
                window.open(url)
                // const params = {
                //     "includeColumnFiledNames": this.headNames
                // }
                // console.log(params)
                // outputData(params).then(res => {
                //     if (res.code === 1) {
                //         this.$message.success('数据导出成功！');
                //     } else {
                //         this.$message.error(res.msg || '操作失败')
                //     }
                // }).catch(err => {
                //     this.$message.error('请求出错了：' + err)
                // })
            },
            async init () {
                const params = {
                    page: this.page,
                    pageSize: this.pageSize,
                    name: this.input ? this.input : undefined,
                    clazzName: this.input1 ? this.input1 : undefined,
                    study: this.input2 ? this.input2 : undefined,
                    school: this.input3 ? this.input3 : undefined,
                    payStatus: this.input4 ? this.input4 : undefined,
                };
                await getStudentList(params).then(res => {//res === res.data
                    if (String(res.code) === '1') {
                        this.tableData = res.data.records || [];
                        this.counts = res.data.total
                        console.log(this.tableData)
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 添加&修改跳转
            addAdminHandle (st) {
                if (st === 'add'){
                    window.parent.menuHandle({
                        id: '1',
                        url: '/back/page/stuFlow/add.html',
                        name: '添加学生'
                    },true)
                } else {
                    window.parent.menuHandle({
                        id: '1',
                        url: '/back/page/stuFlow/add.html?id='+st,//跳转到add.html页面并携带一个id参数
                        name: '查看学生详情'
                    },true)
                }
            },
            handleSizeChange (val) {
                this.pageSize = val;
                this.init()
            },
            handleCurrentChange (val) {
                this.page = val;
                this.init()
            },
        }
    })
</script>
</html>